
//   手机卡类
public class PhoneCard {
    private String cardType;          //成员变量：卡类型
    private String cardId;            //成员变量：卡号
    private String userName;          //成员变量：用户名
    private String password;          //成员变量：密码
    private int accountBalance;       //成员变量：账户余额
    private int callDuration;         //成员变量：通话时长（分钟）
    private int networkData;          //成员变量：上网流量
    private UserConsumeInfo userConsumeInfo;  //消费信息类
    //自定义手机卡的无参构造方法
    public PhoneCard() {
    }
    //自定义手机卡的有参构造方法
    public PhoneCard(String cardType, String cardId, String userName, String password,
                     int accountBalance, int callDuration, int networkData,UserConsumeInfo userConsumeInfo) {
        setCardType(cardType);
        setCardId(cardId);
        setUserName(userName);
        setPassword(password);
        setAccountBalance(accountBalance);
        setCallDuration(callDuration);
        setNetworkData(networkData);
        setUserConsume(userConsumeInfo);
    }



    //提供公有的get和set方法
    public String getCardType() {

    return cardType;
    }

    public void setCardType(String cardType) {

    this.cardType = cardType;
    }
    public String getUserName() {

    return userName;
    }

    public void setUserName(String userName) {

    this.userName = userName;
    }

    public int getAccountBalance() {

    return accountBalance;
    }

    public void setAccountBalance(int accountBalance){
    this.accountBalance = accountBalance;
    }

    public String getCardId() {

    return cardId;
    }

    public void setCardId(String cardId) {

    this.cardId = cardId;
    }

    public String getPassword() {

    return password;
    }

    public void setPassword(String password) {

    this.password = password;
    }

    public int getCallDuration() {

    return callDuration;
    }

    public void setCallDuration(int callDuration) {

    this.callDuration = callDuration;
    }

    public int getNetworkData() {

    return networkData;
    }

    public void setNetworkData(int networkData) {

    this.networkData = networkData;
    }
    public UserConsumeInfo getUserConsumeInfo() {
        return userConsumeInfo;
    }

    public void setUserConsume(UserConsumeInfo userConsumeInfo) {
        this.userConsumeInfo = userConsumeInfo;
    }

     //增加消费方法
    public void addConsume(int consumeValue, int consumeCallDuration, int consumeNetworkData) {
        // 记录消费金额
        getUserConsumeInfo().setConsumeValue(getUserConsumeInfo().getConsumeValue() + consumeValue);
        // 记录通话时长
        getUserConsumeInfo().setConsumeCallDuration(getUserConsumeInfo().getConsumeCallDuration() + consumeCallDuration);
        //记录上网流量
        getUserConsumeInfo().setConsumeNetworkData(getUserConsumeInfo().getConsumeNetworkData() + consumeNetworkData);
    }

    ////自定义成员方法实现显示
    public void showInfo() {
        System.out.println("卡号: " + getCardId()+"用户名：" + getUserName()+"当前余额：" + getAccountBalance() + "元");
        // 打印消费情况
        getUserConsumeInfo().showInfo();

    }

    /**
     * 多态
     * 打印用户所有信息与各类套餐内容
     *
     *
     * @param abstractPackage 套餐抽象类对象
     */
    //自定义一个创建卡的方法
    public void showOnCreate(AbstractPackage... abstractPackage) {
        System.out.printf("卡号：%s\n类型：%s\n用户名：%s\n密码：%s\n时长包：%d分钟\n流量包：%dGB\n当前余额：%d元\n", getCardId(), getCardType(),
                getUserName(), getPassword(), getCallDuration(), getNetworkData(), getAccountBalance());
        for (int i = 0; i < abstractPackage.length; i++) {
            abstractPackage[i].showInfo();
        }
    }


}
